home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 December / maximum-cd-2009-12.iso / DiscContents / gimp-2.7.0-i686-setup.exe / {app} / share / gimp / 2.0 / scripts / select-to-pattern.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2009-08-19  |  3.4 KB  |  104 lines

  1. ; GIMP - The GNU Image Manipulation Program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ;
  4. ; Based on select-to-brush by
  5. ;         Copyright (c) 1997 Adrian Likins aklikins@eos.ncsu.edu
  6. ; Author Cameron Gregory, http://www.flamingtext.com/
  7. ;
  8. ; Takes the current selection, saves it as a pattern and makes it the active
  9. ; pattern
  10. ;
  11. ; This program is free software: you can redistribute it and/or modify
  12. ; it under the terms of the GNU General Public License as published by
  13. ; the Free Software Foundation; either version 3 of the License, or
  14. ; (at your option) any later version.
  15. ;
  16. ; This program is distributed in the hope that it will be useful,
  17. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. ; GNU General Public License for more details.
  20. ;
  21. ; You should have received a copy of the GNU General Public License
  22. ; along with this program.  If not, see <http://www.gnu.org/licenses/>.
  23.  
  24.  
  25. (define (script-fu-selection-to-pattern image drawable desc filename)
  26.  
  27.   (let* (
  28.         (selection-width 0)
  29.         (selection-height 0)
  30.         (selection-bounds 0)
  31.         (select-offset-x 0)
  32.         (select-offset-y 0)
  33.         (pattern-draw-type 0)
  34.         (pattern-image-type 0)
  35.         (pattern-image 0)
  36.         (pattern-draw 0)
  37.         (filename2 0)
  38.         )
  39.  
  40.   (if (= (car (gimp-selection-is-empty image)) TRUE)
  41.       (begin
  42.         (set! selection-width (car (gimp-drawable-width drawable)))
  43.         (set! selection-height (car (gimp-drawable-height drawable)))
  44.       )
  45.       (begin
  46.         (set! selection-bounds (gimp-drawable-mask-bounds drawable))
  47.         (set! select-offset-x (cadr selection-bounds))
  48.         (set! select-offset-y (caddr selection-bounds))
  49.         (set! selection-width (- (cadr (cddr selection-bounds)) select-offset-x))
  50.         (set! selection-height (- (caddr (cddr selection-bounds)) select-offset-y))
  51.       )
  52.   )
  53.  
  54.   (if (= (car (gimp-drawable-has-alpha drawable)) TRUE)
  55.       (set! pattern-draw-type RGBA-IMAGE)
  56.       (set! pattern-draw-type RGB-IMAGE)
  57.   )
  58.  
  59.   (set! pattern-image-type RGB)
  60.  
  61.   (set! pattern-image (car (gimp-image-new selection-width selection-height
  62.                                            pattern-image-type)))
  63.  
  64.   (set! pattern-draw
  65.         (car (gimp-layer-new pattern-image selection-width selection-height
  66.                              pattern-draw-type "Pattern" 100 NORMAL-MODE)))
  67.  
  68.   (gimp-drawable-fill pattern-draw TRANSPARENT-FILL)
  69.  
  70.   (gimp-image-add-layer pattern-image pattern-draw 0)
  71.  
  72.   (gimp-edit-copy drawable)
  73.  
  74.   (let ((floating-sel (car (gimp-edit-paste pattern-draw FALSE))))
  75.     (gimp-floating-sel-anchor floating-sel))
  76.  
  77.   (set! filename2 (string-append gimp-directory
  78.                                  "/patterns/"
  79.                                  filename
  80.                                  (number->string image)
  81.                                  ".pat"))
  82.  
  83.   (file-pat-save 1 pattern-image pattern-draw filename2 "" desc)
  84.   (gimp-patterns-refresh)
  85.   (gimp-context-set-pattern desc)
  86.  
  87.   (gimp-image-delete pattern-image)
  88.   (gimp-displays-flush)
  89.   )
  90. )
  91.  
  92. (script-fu-register "script-fu-selection-to-pattern"
  93.   _"To _Pattern..."
  94.   _"Convert a selection to a pattern"
  95.   "Cameron Gregory <cameron@bloke.com>"
  96.   "Cameron Gregory"
  97.   "09/02/2003"
  98.   "RGB* GRAY*"
  99.   SF-IMAGE     "Image"        0
  100.   SF-DRAWABLE  "Drawable"     0
  101.   SF-STRING   _"Pattern name" "My Pattern"
  102.   SF-STRING   _"File name"    "mypattern"
  103. )
  104.